package com.innovation.chengzhangriji.ui.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import com.innovation.chengzhangriji.R;

public class TimelinePhotoView extends LinearLayout {

    private ImageGroup mImageGroup;

    private CuteTextView mCtvThemeAndText;

    public TimelinePhotoView(Context context) {
        super(context);
        init(context);
    }

    public TimelinePhotoView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public TimelinePhotoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public void setImageGroup(String... urls) {
        mImageGroup.setImageArray(urls);
    }

    public void setThemeAndText(String theme, String text) {
        mCtvThemeAndText.setVisibility(GONE);
        mCtvThemeAndText.setText("");
        String content = "";
        if (!TextUtils.isEmpty(theme)) {
            content = "("+theme+")";
        }
        if (!TextUtils.isEmpty(text)) {
            content = content + " " + text;
        }
        if (TextUtils.isEmpty(content)) {
            return;
        }
        mCtvThemeAndText.setVisibility(VISIBLE);
        mCtvThemeAndText.setText(content);
    }

    public void setOnClickImageListener(ImageGroup.OnClickImageListener listener) {
        mImageGroup.setOnClickImageListener(listener);
    }

    private void init(Context context) {
        setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_card));
        float density = getResources().getDisplayMetrics().density;
        int padL = (int) (16 * density);
        int padR = (int) (14 * density);
        int padY = (int) (12 * density);
        setPadding(padL, padY, padR, padY);
        setOrientation(VERTICAL);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.layout_timeline_photo, this);
        mImageGroup = (ImageGroup) findViewById(R.id.image_group);
        mCtvThemeAndText = (CuteTextView) findViewById(R.id.theme_and_text);
    }
}
